package listeners;

import datacontrol.DAO;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Web application lifecycle listener.
 * Automatically creates the path to the database.
 * 
 * @author Jeroen
 */
public class WebappInitializer implements ServletContextListener {

    // Read the path of the database from the web.xml file
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // Retrieve path from the web.xml
        String dbPath = sce.getServletContext().getInitParameter("databasePath");
        // Set the path to the DAO for further use in the application
        DAO.setDbPath(dbPath);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        
    }
}